<extend name="Public/header" />
<block name="main">
    <link rel="stylesheet" type="text/css" href="http://cdn.datatables.net/1.10.15/css/jquery.dataTables.min.css">
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/weber/webuploader.css" />
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/weber/style.css" />
    <style type="text/css">
        .block{
            display: block;
        }
        .none{
            display: none;
        }
        /*#form{*/
        /*display: block;*/
        /*}*/
    </style>
    <div class="row">
        <div class="col-lg-12">
            <div class="panel panel-default">
                <div class="panel-heading">
                    DataTables Advanced Tables
                </div>
                <!-- /.panel-heading -->
                <div class="panel-body">
                    <button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
                       添加新图片
                    </button>
                    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                        <div class="modal-dialog">
                            <div class="modal-content">
                                <div class="modal-header">
                                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×
                                    </button>
                                    <h4 class="modal-title" id="myModalLabel">
                                       可多图片上传
                                    </h4>
                                </div>
                                <div class="modal-body">
                                    <div style="margin-bottom: 30px;" class="row" style="" id="Doadd">
                                        <div class="col-lg-12" style="border-bottom: 2px solid #ccc;padding: 10px";>
                                            <div id="wrapper" class="upload">
                                                <div id="container">
                                                    <!--头部，相册选择和格式选择-->
                                                    <div id="uploader">
                                                        <div class="queueList">
                                                            <div id="dndArea" class="placeholder">
                                                                <div id="filePicker"></div>
                                                                <p>或将照片拖到这里，单次最多可选300张</p>
                                                            </div>
                                                        </div>
                                                        <div class="statusBar">
                                                            <div class="progress">
                                                                <span class="text">0%</span>
                                                                <span class="percentage"></span>
                                                            </div><div class="info"></div>
                                                            <div class="btns">
                                                                <div id="filePicker2"></div><div class="uploadBtn">开始上传</div>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                            <!--<form role="form" id="form" action='__URL__/Pic/id/{$Think.get.id}/t/add' enctype="multipart/form-data" method="POST">-->
                                                <!--<div class="form-group">-->
                                                    <!--<input type="hidden" value="{$Think.get.id}" name="id">-->
                                                    <!--<label>图片</label>-->
                                                    <!--<input name="file" type="file">-->
                                                <!--</div>-->
                                                <!--<button type="submit" class="btn btn-default">Submit Button</button>-->
                                                <!--<button type="reset" class="btn btn-default">Reset Button</button>-->
                                            <!--</form>-->
                                        </div>
                                    </div>

                                </div>

                            </div><!-- /.modal-content -->
                        </div><!-- /.modal-dialog -->
                    </div><!-- /.modal -->
                    <script>
                        $(function () { $('#myModal').modal('hide')});
                    </script>
                    <script>
                        $(function () { $('#myModal').on('hide.bs.modal', function () {
                            alert('确认要关闭吗？？');})
                        });
                    </script>
                    </div>
                <div class="panel-body">
                <table width="100%" class="table table-striped table-bordered table-hover" id="">
                    <thead>
                    <tr>
                        <th>No.</th>
                        <th>图片</th>
                        <th>状态</th>
                        <th>时间</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <foreach name="list" item="val">
                        <tr class="odd gradeX">
                            <td>{++$i}</td>
                            <td><img width="100" src="__ROOT__{$val.img}" alt=""></td>
                            <td class="center qj">{$val['state'] == 1 ? '启用' : '禁用'}</td>
                            <td class="center">{:date('Y-m-d H:i:s',$val['time'])}</td>
                            <td class="center">
                                <a href=""
                                   data-toggle="modal" data-target="#myupdate"  class="btn btn-outline btn-primary">编辑</a>
                                <a href="javascript:void (0)" class="btn btn-outline btn-success" onclick="qj(this,{$val['id']})">{$val['state'] == 1 ? '隐藏' : '启用'}</a>
                                <a href="{:U('picdel',array('id'=>$val['id']))}"  class="btn btn-outline btn-danger" >删除</a><br>
                            </td>
                        </tr>
                    </foreach>
                    </tbody>
                </table>
                    <div class="row"><div class="col-sm-6"></div>
                        <div class="col-sm-6">
                            <div class="dataTables_paginate paging_simple_numbers" id="dataTables-example_paginate">
                                <div class="pages" style="margin: 0px auto;text-align: center;">
                                    {$page}
                                </div>
                            </div>
                        </div>
                    </div>
                    <!-- 编辑的模态框（Modal） -->
                    <div class="modal fade" id="myupdate" tabindex="-1" role="dialog" aria-labelledby="myupdateLabel" aria-hidden="true">
                        <div class="modal-dialog">
                            <div class="modal-content">
                                <div class="modal-header">
                                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                                        &times;
                                    </button>
                                    <h4 class="modal-title" id="myupdateLabel">
                                        模态框（Modal）标题
                                    </h4>
                                </div>
                                <div class="modal-body">
                                        <form role="form" action="__URL__/Pic/id/{$Think.get.id}/t/update" method="post" enctype="multipart/form-data">
                                            <div id="div">
                                                <label>原图片</label>
                                                <div class="form-group">
                                                    <td><img width="100" src="__ROOT__{$val.img}" id = 'img' alt=""></td>
                                                    <input type="text" value="{val['id']}"  name='id'>
                                                </div>
                                            </div>
                                            <div class="form-group">
                                                <label>轮播图片</label>
                                                <input type="file" name="img">
                                            </div>
                                            <div class="modal-footer">
                                                <button type="submit" class="btn btn-primary" >提交更改</button>
                                            </div>
                                        </form>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

            </div><!-- /.modal-content -->
        </div><!-- /.modal -->
    </div>
    </div>
    </div>
    </div>
    </div>
</block>
<block name='js'>

    <!-- <script type="text/javascript">window.url = '__URL__/Pic'</script>-->
    <!-- ue_end -->
    <script type="text/javascript" src="http://cdn.datatables.net/1.10.15/js/jquery.dataTables.min.js"></script>
    <script type="text/javascript">
        var No = 1;
        window.url = '__URL__/pic/id/{$Think.get.id}/t/add';
        $('#add').click(function(){
            $('#form').attr('action','__URL__/pic/t/add');
            $('#form input').empty();
            if ($(this).html() == '取消') {
                $(this).html('添加新的图片');
                $('#Doadd').hide(); return ;
            }
            $(this).html('取消');
            $('.upload').addClass('block');
            $('.upload').removeClass('none');
            $('#Doadd').show();

        })
        function qj(tha,id) {

            $.ajax({
                type: 'POST',
                data:{id:id},
                url: '{:U("qj")}',
                success: function(dat){
                    console.dir(dat);
                    dat = JSON.parse(dat);
                    alert(dat.message)
                    if(dat.state == 1)
                    {
                        $(tha).html('隐藏')
                        $(tha).parent().parent().find('.qj').html('启用')
                    }else if(dat.state == 2){
                        $(tha).html('启用')
                        $(tha).parent().parent().find('.qj').html('隐藏')
                    }
                },
                error:function () {
                    alert('系统错误')
                }
            })
        }
    </script>
    <script type="text/javascript" src="__PUBLIC__/weber/webuploader.min.js"></script>
    <script type="text/javascript" src="__PUBLIC__/weber/upload.js"></script>
</block>